package javacore.v1ch4;

import java.util.Random;

public class ConstructTest {

    public static void main(String[] args) {
        var staff = new Employ[3];
        staff[0] = new Employ("harry", 40000);
        staff[1] = new Employ(50000);
        staff[2] = new Employ();

        for (Employ e : staff) {
            System.out.println("name" + e.getName() + ",id = " + e.getId() + ",salary = " + e.getSalary());
        }
    }
}

class Employ {
    private static int nextId;
    private int id;
    private String name = "";
    private double salary;

    // 静态块只初始化一次
    static {
        var generator = new Random();

        nextId = generator.nextInt(1000);
        System.out.println("static block initial");
    }

    {
        id = nextId;
        nextId++;
        System.out.println("object block initial");
    }

    public Employ(String n, double s) {
        this.name = n;
        this.salary = s;
        System.out.println("employ is called");
    }

    public Employ() {

    }

    public Employ(double s) {
        this("employ *" + nextId, s);
    }

    public String getName() {
        return name;
    }

    public double getSalary() {
        return salary;
    }

    public int getId() {
        return id;
    }
}
